package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.zigin.commons.util.ReflectUtil;
import net.zigin.nhi.could.waste.dto.SysUserRevicerDto;
import net.zigin.nhi.could.waste.model.SysUserRevicer;
import net.zigin.nhi.could.waste.service.SysUserRevicerService;

import net.zigin.nhi.could.waste.vo.JsonForResult;
import net.zigin.nhi.could.waste.vo.SysUserRevicerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * SysUserRevicer控制器类
 * @ClassName: SysUserRevicerController
 * @author mgw1986
 * @date 2021-9-13 22:41:45
 * @version V1.0
 */
@Api(tags = "接收人管理")
@RestController
@RequestMapping("/sysUserRevicer")
public class SysUserRevicerController extends BaseController {
	@Autowired
	private SysUserRevicerService sysUserRevicerService;

	@ApiOperation("保存编辑接收人")
	@ApiImplicitParam(name = "sysUserRevicerDto", value = "接收人信息", required = true, dataType = "SysUserRevicerDto")
	@PostMapping("/save")
	public JsonForResult<String> save(@RequestBody SysUserRevicerDto sysUserRevicerDto){
		String id = sysUserRevicerService.saveOrUpdate(sysUserRevicerDto);
		return JsonForResult.<String>builder().data(id).success(true).build();
	}

	@ApiOperation("接收人列表")
	@PostMapping("/getList")
	public JsonForResult<List<SysUserRevicerVo>> getList(){
		List<SysUserRevicerVo> list = sysUserRevicerService.getList();
		return JsonForResult.<List<SysUserRevicerVo>>builder().data(list).success(true).build();
	}

	@ApiOperation("默认接收人")
	@PostMapping("/getDefault")
	public JsonForResult<SysUserRevicerVo> getDefault(){
		SysUserRevicerVo vo = sysUserRevicerService.getDefault();
		return JsonForResult.<SysUserRevicerVo>builder().data(vo).success(true).build();
	}

	@ApiOperation("接收人详情")
	@ApiImplicitParam(name = "id", value = "接收人id", required = true, dataType = "String")
	@GetMapping("/getById/{id}")
	public JsonForResult<SysUserRevicerVo> getById(@PathVariable String id){
		SysUserRevicer sysUserRevicer = sysUserRevicerService.selectByPrimaryKey(id);
		SysUserRevicerVo vo = ReflectUtil.copyProperties(sysUserRevicer, SysUserRevicerVo.class);
		return JsonForResult.<SysUserRevicerVo>builder().data(vo).success(true).build();
	}

	@ApiOperation("设置默认接收人")
	@ApiImplicitParam(name = "id", value = "接收人id", required = true, dataType = "String")
	@GetMapping("/setDefault/{id}")
	public JsonForResult setDefault(@PathVariable String id){
		sysUserRevicerService.setDefault(id);
		return JsonForResult.builder().success(true).build();
	}

	@DeleteMapping("/remove/{id}")
	@ApiOperation("删除接收人")
	@ApiImplicitParam(name = "id", value = "接收人id", required = true, dataType = "String")
	public JsonForResult remove(@PathVariable String id){
		sysUserRevicerService.deleteByPrimaryKey(id);
		return JsonForResult.builder().success(true).build();
	}

}
